<?php
use loader\SplClassLoader;
use classes\bank\Bank;
use classes\bank\Credit;
use classes\bank\Deposit;
use classes\bank\ShortDeposit;
use classes\bank\LongDeposit;
use classes\Bank\HomeCredit;
use classes\Bank\ConsumerCredit;
use classes\customer\Customer;

try {
set_error_handler("error_handler");
//error_reporting(0);
require 'loader/SplClassLoader.php';
$loader = new loader\SplClassLoader();
$loader->register();

$bank1 = new Bank("Uni", "dds", 10000);
$bank1->showInfo();
$arrCus = array();
$customer1 = new Customer("Ivan", "dds", 20000, 3000);
$customer1->showInfo();
$customer2 = new Customer("Penka", "dre", 10000, 5000);
$customer2->showInfo();
$customer3 = new Customer("Stoqnka", "dft", 5000, 6000);
$customer3->showInfo();

array_push($arrCus, $customer1);
array_push($arrCus, $customer2);
array_push($arrCus, $customer3);

for($i=0; $i<3; $i++){
	$rand = rand (8, 10) / 10;
	$curSum = $rand * $arrCus[$i]->getMoney();
	$deposit1 = new ShortDeposit($i, 3, $curSum);
	$deposit1->showInfo();
	$arrCus[$i]->makeDeposit($bank1, $deposit1, $arrCus[$i]);
} 

$bank1->payLihviPoVsichkiDepoziti();
$bank1->giveCredit(20, 1000, 12, $customer1, "HOME_CREDIT");
$bank1->giveCredit(21, 500, 12, $customer1, "CONSUMER_CREDIT");

$bank1->showInfo();

} catch (Exception $e) {
	echo $e->getMessage();
// 	echo $e->getCode();
// 	echo $e->getFile();
}

function error_handler($errno, $errmsg, $filename, $linenum, $vars)
{
	$file = fopen("error/error.log", "a");
	echo '</br>';
	echo "<p style = 'color: red'>Calling Project Error Handler...</p>";
	echo "Error message: $errmsg</br>";
	echo "File name: $filename</br>";
	echo "Line: $linenum</br>";
	$errorMsg = "Error number: $errno Error message: $errmsg File name: $filename Line: $linenum \n";
	fwrite($file, $errorMsg);
	fclose($file);
}